package jpa.Model;

import javax.persistence.*;
import java.util.Set;

/**
 * Created by IntelliJ IDEA.
 * User: Pavlo
 * Date: 30.01.12
 * Time: 15:00
 * To change this template use File | Settings | File Templates.
 */
@Entity
@Table(name = "District")
public class District extends ID {

    private String name;

    private String address;

    private DistrictType type;

    private Set<Person> members;

    private Set<Protocol> protocols;

    @Column(name = "name", unique = false, nullable = false)
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    @ManyToOne
    @JoinColumn(name = "type", referencedColumnName = "ID")
    public DistrictType getType() {
        return type;
    }

    public void setType(DistrictType type) {
        this.type = type;
    }

    @ManyToMany(cascade = CascadeType.ALL)
    @JoinTable(name = "DistrictSquad",
            joinColumns = @JoinColumn(name = "districtID", referencedColumnName = "ID"),
            inverseJoinColumns = @JoinColumn(name = "personID", referencedColumnName = "ID")
    )
    public Set<Person> getMembers() {
        return members;
    }

    public void setMembers(Set<Person> members) {
        this.members = members;
    }

    @OneToMany
    @JoinColumn(name = "district")
    public Set<Protocol> getProtocols() {
        return protocols;
    }

    public void setProtocols(Set<Protocol> protocols) {
        this.protocols = protocols;
    }
}
